package com.example.Controller;


import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;

import com.example.Service.LoginService;
import com.example.entity.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user")
@CrossOrigin
public class LoginController {
    @Autowired
    LoginService loginService;
    @PostMapping("/login")
    public SaResult login(@RequestBody Users users) {
        Users user = loginService.login(users);
        if (user != null) {
            SaResult res = SaResult.data(user);
            res.set("token", StpUtil.getTokenValue());
            return res;
        }else {
            return SaResult.error("登录失败");
        }
    }
}